package checkers3d.presentation;

import java.awt.*;

public class RenderResourceText implements IRenderResource//Resource for Text based rendering.
{
    private Color color = null;
    private String text = null;
    private int pixelWidth = 0;

    public RenderResourceText(String text1, Color color1)//Constructor.  Creates resource from specified text and color.
    {
        setText(text1);
        setColor(color1);
        recalculateWidth();
    }

    public void setColor(Color color)//Sets color of Text
    {
        this.color = color;
    }

    public boolean containsPoint(Point point)//see interface
    {
        //HACK: Reda needs to fix this.
        if (point.x > getWidth() || point.y > getHeight() ||
            point.x < 0          || point.y < 0)
        {
            return false;
        }
        else
        {
            return true;
        }

    }

    public void recalculateWidth()
    {
        pixelWidth = 0;

        char[] characters = text.toCharArray();

        for(int i = 0; i < characters.length; i++)
        {
            switch (characters[i])
            {
                case 'a': pixelWidth += 7; break;
                case 'b': pixelWidth += 7; break;
                case 'c': pixelWidth += 6; break;
                case 'd': pixelWidth += 7; break;
                case 'e': pixelWidth += 7; break;
                case 'f': pixelWidth += 3; break;
                case 'g': pixelWidth += 7; break;
                case 'h': pixelWidth += 7; break;
                case 'i': pixelWidth += 3; break;
                case 'j': pixelWidth += 3; break;
                case 'k': pixelWidth += 6; break;
                case 'l': pixelWidth += 3; break;
                case 'm': pixelWidth += 11; break;
                case 'n': pixelWidth += 7; break;
                case 'o': pixelWidth += 7; break;
                case 'p': pixelWidth += 7; break;
                case 'q': pixelWidth += 7; break;
                case 'r': pixelWidth += 4; break;
                case 's': pixelWidth += 6; break;
                case 't': pixelWidth += 4; break;
                case 'u': pixelWidth += 8; break;
                case 'v': pixelWidth += 6; break;
                case 'w': pixelWidth += 10; break;
                case 'x': pixelWidth += 6; break;
                case 'y': pixelWidth += 6; break;
                case 'z': pixelWidth += 6; break;
                case '*': pixelWidth += 5; break;
                default:
                    pixelWidth += 8;
            }
        }
    }

    public int getHeight()
    {
        //TODO: huh?
        return 9;
    }

    public int getWidth()
    {
        return pixelWidth;
    }

    public void reset()
    {
        //do nothing.
    }
    
    public void tick(int ms)
    {
        //do nothing.
    }

    public Color getColor()//Returns color of text
    {
        return color;
    }

    public String getText()//Returns text string.
    {
        return text;
    }

    public void setText(String text)//Sets text string
    {
        this.text = text;
        
        recalculateWidth();
    }

    @Override
    public IRenderResource clone()
    {
        RenderResourceText copy = new RenderResourceText(null, null);

        copy.setText(new String(getText()));
        copy.setColor(new Color(getColor().getRGB()));
        
        copy.recalculateWidth();
        
        return copy;
    }
}
